<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
* @version $Id: checkout.paybox_cc_form.php  
* @package VirtueMart
* @subpackage html
* @author Fetsch Fabrice  <fabrice.fetsch(at)keoconcept.com>
* 				Val�rie Isaksen <valerie.isaksen@alatak.net>
* @copyright Copyright (C) 2004-2005 Soeren Eberhardt. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* The ps_paybox class, containing the payment processing code
*  for transactions with  PAYBOX Payment Gateways 
*
*  
*
*/
mm_showMyFileName( __FILE__ );

require_once(  CLASSPATH."payment/ps_paybox_n.cfg.php");
require_once(  CLASSPATH."payment/ps_paybox_n.php");
$PAYBOX_LANG =& new ps_paybox_Language();

global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_lang, $ps_vendor_id , $vendor_country_2_code;
global $VM_LANG, $Itemid;

$dbb = new ps_DB;
$q = "SELECT * FROM jos_vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

$amount = $db->f("order_total")*100;
$url_ok = SECUREURL ."index.php?option=com_virtuemart&amp;page=checkout.paybox_result&amp;status=ok";
$url_cancelled =  SECUREURL ."index.php?option=com_virtuemart&amp;page=checkout.paybox_result&amp;status=cancel";
$url_deny = SECUREURL ."index.php?option=com_virtuemart&amp;page=checkout.paybox_result&amp;status=deny";
//$url_error = SECUREURL."administrator/components/com_virtuemart/html/checkout.paybox_error.php";
$url_error = SECUREURL."paybox_error.php";
$url = PAYBOX_MOD_URL;
// ajout URL http dynamique
$url_http = SECUREURL."paybox_url_http.php";

$montant_total= $amount;
$echeance = round($amount / PAYBOX_NB_ECHEANCE, 0);
$montant_total=$montant_total-$echeance*(PAYBOX_NB_ECHEANCE-1);
 
$post_variables = Array(
"PBX_MODE" => "13" ,
"PBX_DEVISE" =>  PAYBOX_CURRENCY ,
//Modif ajout prefixe
"PBX_CMD" =>  PAYBOX_PREFIX. "-" . $db->f("order_id") ,
// fin modif
"PBX_DIFF" =>  PAYBOX_DIFF ,
"PBX_LANGUE" =>  PAYBOX_LANG ,
"PBX_PORTEUR" =>  $dbb->f("user_email"),
/* Paiement initial */
"PBX_TOTAL" =>  $montant_total,

"PBX_EFFECTUE" =>   $url_ok ,
"PBX_ANNULE" =>   $url_cancelled ,
"PBX_REFUSE" =>  $url_deny ,
"PBX_ERREUR" =>  $url_error,
// variable url http
"PBX_REPONDRE_A" => $url_http,
"PBX_OPT" =>  CLASSPATH."payment/ps_paybox_n_local.txt" ,
"PBX_RETOUR" => "transactionnum:S;bankauth:A;transactionid:T;vmref:R;amount:M;pbxerror:E"
);
 
for ($i=1 ; $i <PAYBOX_NB_ECHEANCE; $i++ ) {
	$pbxmont="PBX_2MONT".$i;
	$post_variables [$pbxmont]= $echeance;
	$datex="PBX_DATE".$i;
	$post_variables [$datex]= strftime  ( "%d/%m/%Y"  ,   mktime(0,0,0,date("m" ) + $i  ,date("d" ) ,date("Y" )) );
}

// On zappe la page
if( $page == "checkout.thankyou" ) {
	$query_string = "?";
	foreach( $post_variables as $name => $value ) {
		$query_string .= $name. "=" . urlencode($value) ."&";
	}
	vmRedirect( $url . $query_string );
} else { 
	echo '<form action="'.PAYBOX_MOD_URL.'" method="post" >';
	echo '<input type="image" name="submit" src="'.IMAGEURL.'payment/paybox.gif" border="0" alt="Paiement avec Paybox!">';

	foreach( $post_variables as $name => $value ) {
		echo '<input type="hidden" name="'.$name.'" value="'.$value.'" />';
	}
	echo '</form>';
}
?>

